package com.pe.pgn.clubpgn.webapp.controller.reportereservacanje;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.pe.pgn.clubpgn.domain.beans.BNDocumentoMovArticulo;
import com.pe.pgn.clubpgn.domain.beans.BNReporteReserva;
import com.pe.pgn.clubpgn.service.ReporteReservaCanjeService;
import com.pe.pgn.clubpgn.webapp.controller.BaseFormController;

@Controller
@RequestMapping("/reportereservacanje/**")
public class ReporteReservaCanjeController extends BaseFormController{
	
	@Autowired
	private ReporteReservaCanjeService reporteReservaCanjeService;
	
	@RequestMapping(value = "/reportereservacanjelist.html")
    public @ModelAttribute("reservaform") BNReporteReserva listarDocumentosDevolucion(
    	@ModelAttribute("reservaform") BNReporteReserva bndocumento,
        @RequestParam(value = "search", required = false) String search, Model model){
		
		if(StringUtils.isBlank(search)){
			
			List<BNDocumentoMovArticulo> reservas = reporteReservaCanjeService.listaReporteReservaCanje();
			model.addAttribute("reservas", reservas);
			
		}else{
			
			List<BNDocumentoMovArticulo> reservas = reporteReservaCanjeService.busquedaListaReporteReservaCanje(
			bndocumento.getFechaInicio(), bndocumento.getFechaFin(), bndocumento.getDaHoraInicio(),bndocumento.getDaHoraFin());
			model.addAttribute("reservas", reservas);
		}		
		
		return bndocumento;
    }	
}
